from django import forms
from captcha.fields import CaptchaField


class UserForm(forms.Form):
    username = forms.CharField(label="用户名", max_length=18, min_length=2, required=True, error_messages=
    {
        'required': '用户名不能为空',
        'max_length': '用户名过长',
        'min_length': '用户名过短',
        'invalid': '格式输入有误'
    }, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "请输入您的用户名"}))
    password = forms.CharField(label="密码", max_length=18,
                               widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': "请输入您的密码"}),
                               min_length=6, required=True,
                               error_messages=
                               {
                                   'required': '密码不能为空',
                                   'max_length': '密码过长',
                                   'min_length': '密码过短',
                                   'invalid': '格式输入有误'
                               })
    captcha = CaptchaField(label='验证码')


class RegisterForm(forms.Form):
    username = forms.CharField(label='用户名', max_length=18,
                               widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "请输入您的用户名"}),
                               min_length=2, required=True, error_messages=
                               {
                                   'required': '用户名不能为空',
                                   'max_length': '用户名过长',
                                   'min_length': '用户名过短',
                                   'invalid': '格式输入有误'
                               })
    real_name = forms.CharField(label='真实姓名(选填)', max_length=18,
                                widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "请输入您的真实姓名"}),
                                min_length=2, required=False, error_messages=
                                {
                                    'required': '姓名不能为空',
                                    'max_length': '姓名过长',
                                    'min_length': '姓名过短',
                                    'invalid': '格式输入有误'
                                })
    password = forms.CharField(label='密码', max_length=18, min_length=6, required=True, error_messages=
    {
        'required': '密码不能为空',
        'max_length': '密码过长',
        'min_length': '密码过短',
        'invalid': '格式输入有误'
    },
                               widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': "请输入您的密码"}))
    password_confirm = forms.CharField(label='确认密码', max_length=256, widget=forms.PasswordInput(
        attrs={'class': 'form-control', 'placeholder': "请再输入一遍密码"}))
    email = forms.EmailField(label='电子邮件地址(选填)', required=False, min_length=3, max_length=18,
                             widget=forms.EmailInput(attrs={'class': 'form-control', 'placeholder': "请输入您的电子邮箱地址"}))
    captcha = CaptchaField(label='图形验证码')


class ContentForm(forms.Form):
    content = forms.CharField(label='内容', max_length=2048, min_length=6, required=True, error_messages=
    {
        'required': '内容不能为空',
        'max_length': '内容过长',
        'min_length': '内容过短',
        'invalid': '格式输入有误'
    },
                              widget=forms.Textarea(attrs={'class': 'form-control', 'placeholder': "请输入内容"}))

    titleItem = forms.CharField(label='标题', max_length=20, min_length=2, required=True, error_messages=
    {
        'required': '标题不能为空',
        'max_length': '标题过长',
        'min_length': '标题过短',
        'invalid': '格式输入有误'
    },
                                widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "请输入标题"}))


class DiscussForm(forms.Form):
    discuss = forms.CharField(label='内容', max_length=2048, min_length=6, required=True, error_messages=
    {
        'required': '内容不能为空',
        'max_length': '内容过长',
        'min_length': '内容过短',
        'invalid': '格式输入有误'
    },
                              widget=forms.Textarea(attrs={'class': 'form-control', 'placeholder': "请输入内容(来吧, 尽情发挥~)"}))

    discuss_title = forms.CharField(label='标题', max_length=20, min_length=2, required=True, error_messages=
    {
        'required': '标题不能为空',
        'max_length': '标题过长',
        'min_length': '标题过短',
        'invalid': '格式输入有误'
    },
                                    widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "请输入标题"}))


class NewsForm(forms.Form):
    news_title = forms.CharField(label='新闻标题', max_length=20, min_length=2, required=True, error_messages=
    {
        'required': '标题不能为空',
        'max_length': '标题过长',
        'min_length': '标题过短',
        'invalid': '格式输入有误'
    },
                                 widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "请输入标题"}))
    news_content = forms.CharField(label='内容', max_length=2048, min_length=6, required=True, error_messages=
    {
        'required': '内容不能为空',
        'max_length': '内容过长',
        'min_length': '内容过短',
        'invalid': '格式输入有误'
    },
                                   widget=forms.Textarea(attrs={'class': 'form-control', 'placeholder': "请输入内容"}))


class TipForm(forms.Form):
    tip_content = forms.CharField(label='内容', max_length=50, min_length=6, required=True, error_messages=
    {
        'required': '内容不能为空',
        'max_length': '内容过长',
        'min_length': '内容过短',
        'invalid': '格式输入有误'
    },
                                  widget=forms.Textarea(attrs={'class': 'form-control', 'placeholder': "请输入内容"}))


class UserCentralForm(forms.Form):
    old_psw = forms.CharField(label='旧密码', max_length=18, min_length=6, required=True, error_messages=
    {
        'required': '密码不能为空',
        'max_length': '密码过长',
        'min_length': '密码过短',
        'invalid': '格式输入有误'
    },
                              widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': "请输入您的旧密码"}))
    new_psw = forms.CharField(label='新密码', max_length=18, min_length=6, required=True, error_messages=
    {
        'required': '密码不能为空',
        'max_length': '密码过长',
        'min_length': '密码过短',
        'invalid': '格式输入有误'
    },
                              widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': "请输入您的新密码"}))

    new_psw_confirm = forms.CharField(label='确认密码', max_length=18, min_length=6, required=True, error_messages=
    {
        'required': '密码不能为空',
        'max_length': '密码过长',
        'min_length': '密码过短',
        'invalid': '格式输入有误'
    },
                                      widget=forms.PasswordInput(
                                          attrs={'class': 'form-control', 'placeholder': "确认密码"}))

    real_name = forms.CharField(label='真实姓名', max_length=18,
                                widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "请输入您的姓名"}),
                                min_length=2, required=False, error_messages=
                                {
                                    'required': '姓名不能为空',
                                    'max_length': '姓名过长',
                                    'min_length': '姓名过短',
                                    'invalid': '格式输入有误'
                                })
